package demo;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-06
 * Time: 18:12
 */
public class CardList {
    private static final String[] SUITS = {"♦","♥","♠","♣"};
    //生成扑克牌
    public static List<Card> buyCard(){

        List<Card> list = new ArrayList<>();//实例化顺序表

        for (int i = 0; i < SUITS.length; i++) {
            //String suit = SUITS[i];
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(SUITS[i],j);
                list.add(card);
            }
        }
        return list;
    }
    //洗牌
    public static void shuffle(List<Card> list){
        Random random = new Random();

        for (int i = 51; i > 0; i--) {
            int index = random.nextInt(i);
            swap(list,i,index);
        }
    }
    //交换
    public static void swap(List<Card> list,int i,int j){
        Card temp = list.get(i);
        list.set(i,list.get(j));
        list.set(j,temp);
    }

    public static void main(String[] args) {
        List<Card> list = buyCard();
        //
        System.out.println(list);
        System.out.println("------------------------");
        /*List<Card> list = CardList.buyCard();
        System.out.println(list);
        System.out.println("------------------------");*/
        shuffle(list);
        //
        System.out.println(list);

        List<List<Card>> hand = new ArrayList<>();

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }
        //
        System.out.println("第一个人的牌"+hand.get(0));
        System.out.println("第二个人的牌"+hand.get(1));
        System.out.println("第三个人的牌"+hand.get(2));
        System.out.println(list);
    }
}
